package ru.ya.kolemik;

import org.springframework.beans.factory.InitializingBean;

public class TrayCommandBean implements TrayCommand, InitializingBean{

	private String command;
	
	private Process process;

	private String label;
	
	public void setCommand(String command) {
		this.command = command;
	}

	@Override
	public Process getProcess() {
		return process;
	}

	@Override
	public void start() throws Exception {
		Runtime rt = Runtime.getRuntime();
		process = rt.exec(command);
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		// Do nothing
	}

	@Override
	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	@Override
	public void stop() {
		if (process != null) {
			process.destroy();
		}
	}

}
